<template>
	<view class="page">
		<u-sticky z-index="999" offset-top="0">
			<view>
				<!-- TODO 这里需要判断没订单，跳出空白提示，并且可以分页加载 -->
				<u-navbar :is-fixed="false" :borderBottom=false title-color="#FFFFFF" back-icon-color="#FFFFFF"
					title="订单列表" :background="background" @rightClick="rightClick" :autoBack="true">
				</u-navbar>
				<u-tabs :bold="true" active-color="#FFFFFF" inactive-color="#FFFFFF" bg-color="#00C785" name="cate_name"
					count="cate_count" :list="list" :is-scroll="true" :current="current" @change="change">
				</u-tabs>
			</view>
		</u-sticky>
		<view class="orders" style="margin: 30rpx;">
			<view @click="toDetail(item.id)" v-for="(item,index) in orders" :key="index" class="list-item flex-col">
				<view class="top-group justify-between">
					<view class="left-group flex-row">
						{{item.updated_at}}
						<!-- <text>2021-08-03</text>
						<text class="text_8">14:21:12</text> -->
					</view>
					<text :style="{color : item.status == 3 ? 'grey':'rgba(0, 199, 133, 0.99)'}"
						class="text_10">{{list[item.status].cate_name}}</text>
				</view>
				<view class="bottom-group flex-row">
					<image :src="item.goods.format_image" class="image_5" />
					<view class="right-group flex-col">
						<text class="text_12">{{item.goods.name}}</text>
						<text class="text_14">最高预估可卖</text>
						<view class="bottom-group_1 flex-row">
							<text class="text_16">￥</text>
							<text class="text_18">{{item.goods_price}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore v-if="orders != []" icon-color="#00C785" color="#00C785" @loadmore="loadmore" margin-bottom="20"
			:load-text="loadText" :status="status" />
	</view>
</template>

<script>
	import {
		tiao
	} from '@/utils/common.js'
	import {
		getOrder
	} from '@/api/index.js'
	export default {
		data() {
			return {
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '正在加载，请喝杯茶...',
					nomore: '实在没有了'
				},
				background: {
					backgroundColor: '#00C785',
				},
				status: 'loadmore',
				page: 1,
				row: 5,
				list: [{
					cate_name: '全部'
				}, {
					cate_name: '待发货',
				}, {
					cate_name: '已发货/待验收',
				}, {
					cate_name: '已收货/待评估',
				}, {
					cate_name: '已评估/寄卖中',
				}, {
					cate_name: '完成',
				}],
				current: 0,
				orders: [],
				showOrder: [],
				flag:false,
			}
		},
		onReachBottom() {
			if(this.flag){
				this.getData();
				this.status = 'laoding'
			}else{
				this.status = 'nomore'
			}
		},
		onLoad(res) {

			this.getData(res.index);
		},
		methods: {
			toDetail(id) {
				tiao('/pages/order-detail/order-detail', {
					id
				})
			},
			getData(index) {
				getOrder().then(res => {
					console.log("订单", res);
					if(res.page < res.last_page){
						this.page++
						this.flag = true
					}else{
						this.flag = false
					}
					this.orders = res.data.data
					this.showOrder = res.data.data
					this.status ="nomore"
					this.change(index)
				})
			},
			loadmore(){
				
			},
			change(e) {
				this.page=1
				console.log(e);
				this.current = e;
				this.page = 1;
				if (e != 0) {
					this.orders = this.showOrder.filter(item => {
						return item.status == e
					})
				} else {
					this.orders = this.showOrder
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list-item {
		padding: 0 30rpx;
		background-color: rgb(255, 255, 255);
		box-shadow: 0px 2rpx 20rpx 0px rgba(0, 0, 0, 0.05);
		border-radius: 10rpx;

		&:not(:first-of-type) {
			margin-top: 30rpx;
		}

		.top-group {
			padding: 30rpx 0 19rpx;
			border-bottom: solid 2rpx rgb(238, 238, 238);

			.left-group {
				color: rgb(102, 102, 102);
				font-size: 24rpx;
				line-height: 33rpx;
				white-space: nowrap;

				.text_8 {
					margin-left: 16rpx;
				}
			}

			.text_10 {
				color: rgba(0, 199, 133, 0.99);
				font-size: 24rpx;
				line-height: 33rpx;
				white-space: nowrap;
			}
		}

		.bottom-group {
			padding: 20rpx 0 31rpx;

			.image_5 {
				border-radius: 10rpx;
				width: 120rpx;
				height: 120rpx;
			}

			.right-group {
				margin-left: 20rpx;

				.text_12 {
					color: rgb(68, 68, 68);
					font-size: 28rpx;
					font-weight: 500;
					line-height: 40rpx;
					white-space: nowrap;
				}

				.text_14 {
					margin-top: 4rpx;
					color: rgb(153, 153, 153);
					font-size: 20rpx;
					line-height: 28rpx;
					white-space: nowrap;
				}

				.bottom-group_1 {
					margin-top: 6rpx;

					.text_16 {
						margin-top: 13rpx;
						color: rgb(0, 199, 133);
						font-size: 20rpx;
						font-weight: 500;
						line-height: 28rpx;
						white-space: nowrap;
					}

					.text_18 {
						margin-left: 4rpx;
						color: rgb(0, 199, 133);
						font-size: 32rpx;
						font-weight: 600;
						line-height: 45rpx;
						white-space: nowrap;
					}
				}
			}
		}
	}
</style>